home *** CD-ROM | disk | FTP | other *** search
- Path: keats.ugrad.cs.ubc.ca!not-for-mail
- From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku)
- Newsgroups: comp.lang.c
- Subject: Re: hex to dec function?
- Date: 3 Mar 1996 22:11:20 -0800
- Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
- Message-ID: <4he1i8INNbmc@keats.ugrad.cs.ubc.ca>
- References: <4gdh1b$bg@mailhost.mwmicro.com> <4gg3h0INN59e@keats.ugrad.cs.ubc.ca> <danpop.824997504@rscernix> <4hab7t$uo4@news.vcnet.com>
- NNTP-Posting-Host: keats.ugrad.cs.ubc.ca
-
- In article <4hab7t$uo4@news.vcnet.com>,
- Carl Jacobson <swedecj@vcnet.com> wrote:
- >Why does the following hang my pc when the printf statement is being
-
- Because your PC's so-called OS is not robust enough to protect it self from an
- insignificant little programming bug.
-
- >executed. If I put a breakpoint on the printf, watch and reset,
- >everything seems OK up to that point. The answer appears to be in the
- >above comments, but I do not understand the premise.
- >
- > char *pref = "0x";
- > char *suff;
- > long numb;
- >
- > scanf("%s",suff);
-
- Suff is an unitialized pointer. It points to no valid storage. You could have
- declared suff as a character array, char suff[20];
-
- Using "%s" in scanf without a numeric restriction, such as "%19s", is so bad,
- you might as well use gets().
-
- > strcat(pref,suff);
-
- This is incorrect. You are trying to write to a string literal, which is
- illegal. Furthermore, you are trying to write _past_ the literal, which is
- absolutely taboo.
-
- > sscanf(pref,"0x%lx",&numb);
-
- You don't need to scan the 0x prefix. Why not check a reference like the K&R2
- if you are not sure?
- --
-
-